<?
class clsProduct extends yellowpages{
 var $lk;
 /*function clsProduct($lk){
  $this->lk = "%$lk%";
  if(strpos($lk,'%')!==false) $this->lk=$lk;
 }*/
 function sql(){
  $a = func_get_args(); $no='';// print_r($a);
  if($a[3]=='vn') $no = yellowpages::checkVn($a[1]);
  switch($a[0]){
   case 'product':
	$sql="SELECT x_ref_id, class_name_us, class_name_vn, class_name_cn, count(class_id) as num 
		  FROM class, id_class 
		  WHERE (class.x_ref_id = id_class.class_id_1) and class_name_$a[3]$no LIKE '".$this->lk."'
		  GROUP BY class_name_$a[2]
		  ORDER BY class_name_$a[3]";
    break;
   case "company":
    $sql="select idall from company_name where company_$a[3]$no like '%".$a[1]."%'";
	break;
   case "trade name":
    $sql="select trade_id from trade_name,id_trade where (trade_name.trade_id=id_trade.trade_name_1) and 
		 trade_name like '".$a[1]."%'";
	break;
   case "tel/fax":
    $sql="select idall from no_tel where tel_fax like '".$a[1]."%'";
	break;
  }
  //echo("$sql<br>");
  return $sql;
 }
 function showResult(){//'product', $txtsearch, $lang, $lang,$ids,$lglnk
  $a = func_get_args(); $k = array(); $this->lk="%$a[1]%";
  if(isset($_REQUEST['kt'])){
   $this->lk="$a[1]%";
   $pro=$this->resultProduct($a[0],$a);
  }else{
   $pro=$this->resultProduct($a[0],$a);
   $com=$this->resultCompany('company',$a);// print_r($com);
   if(empty($com)) $com=array('','','');
   $trade=$this->resultCompany('trade name',$a);// print_r($trade);
   if(empty($trade)) $trade=array('','','');
   $tel=$this->resultCompany('tel/fax',$a);
   if(empty($tel)) $tel=array('','','');
  }
  $tmpus=$com[0].$trade[0].$tel[0];
  $tmpvn=$com[1].$trade[1].$tel[1];
  $tmpcn=$com[2].$trade[2].$tel[2];
  if($a[2]=='us') $a[2]='';
  if($tmpus){ 
   $tmpus="<tr><td class='font13 khl khr kht' bgcolor=#1B90D5 height=18>Could you be looking for</td></tr>
           <tr><td class='khl khr' height=2></td></tr>$tmpus";
   $tmpvn="<tr><td class=font13 bgcolor=#1B90D5 height=18 style=padding-left:5px>Bạn có thể tìm theo</td></tr>
   		   <tr><td height=5></td></tr>$tmpvn";
   $tmpcn="<tr><td class=font13 bgcolor=#1B90D5 height=18 style=padding-left:5px>搜索任何有关</td></tr>
   		   <tr><td height=5></td></tr>$tmpcn";
  }
  $k[]=$pro[0]; $k[]=$pro[1]; $k[]=$pro[2]; $k[]=$tmpus; $k[]=$tmpvn; $k[]=$tmpcn;
  return $k;
 }
 function resultProduct(){
  $a 	  = func_get_args(); $k = array('','',''); $i=0;
  $sql	  = $this->sql($a[0],$a[1][1],$a[1][2],$a[1][3]);// echo("$sql <br>");
  $result = mysql_query($sql) or die('counld not query');
  $t="<tr><td height=20 width=180 bgcolor=#1B90D5 class=font13 style=padding-left:5px><b>Product & Service</b></td></tr>
  	  <tr><td style=padding-bottom:10px><div class=menu><div id=ismenu class=scr><table class=tab width=100%>";
  $tvn="<tr><td height=20 width=180 bgcolor=#1B90D5 class=font13 style=padding-left:5px><b>Sản Phẩm & Dịch vụ</b></td></tr>
  	  <tr><td style=padding-bottom:10px><div class=menu><div id=ismenu class=scr><table class=tab width=100%>";
  $tcn="<tr><td height=20 width=180 bgcolor=#1B90D5 class=font13 style=padding-left:5px><b>消费及商务分类项目</b></td></tr>
  	  <tr><td style=padding-bottom:10px><div class=menu><div id=ismenu class=scr><table class=tab width=100%>";	
  if(!mysql_num_rows($result)) return 0;
  while($rs=mysql_fetch_array($result,MYSQL_NUM)){
   $k[0].="<tr><td><table class='tab fn11' cellpadding=0 cellspacing=0>
   		<tr><td class=pdr5 style=padding-top:3px valign=top><img src=images/muiten.gif></td></td>
		<td><a id=lng class=text-grey href=puttype.php?ids=".$a[1][4]."&key=$rs[0]&word=".base64_encode($rs[1])."&kind=productList&lang=us&pos=$i title='$rs[1]'>$rs[1]</a> ($rs[4])</td>
		</tr></table></td></tr>";
   $k[1].="<tr><td><table class='tab fn11' cellpadding=0 cellspacing=0>
   		<tr><td class=pdr5 style=padding-top:3px valign=top><img src=images/muiten.gif></td>
		<td><a id=lng class=text-grey href=puttype.php?ids=".$a[1][4]."&key=$rs[0]&word=".base64_encode($rs[2])."&kind=productList&lang=vn&pos=$i title='$rs[2]'>$rs[2]</a> ($rs[4])</td>
		</tr></table></td></tr>";
   $k[2].="<tr><td><table class='tab fn11' cellpadding=0 cellspacing=0>
   		<tr><td class=pdr5 style=padding-top:3px valign=top><img src=images/muiten.gif></td>
		<td><a id=lng class=text-grey href=puttype.php?ids=".$a[1][4]."&key=$rs[0]&word=".base64_encode($rs[3])."&kind=productList&lang=cn&pos=$i title='$rs[3]'>$rs[3]</a> ($rs[4])</td>
		</tr></table></td></tr>";
  $i++;
  }
  mysql_free_result($result);
  $k[0]= $t."$k[0]</table></div></div></td></tr>";
  $k[1]= $tvn."$k[1]</table></div></div></td></tr>";
  $k[2]= $tcn."$k[2]</table></div></div></td></tr>";
  return $k;
 }
 function resultCompany(){//'product', $txtsearch, $lang, $lang, $ids, $lglnk
  $a = func_get_args(); //print_r($a);
  $nmProUs = array('Companies with Name containing','Brand with Name containing','Any Tel/Fax have to');
  $nmProVn = array('Công ty có tên chứa từ','Thương hiệu liên quan','Số Tel/Fax liên quan');
  $nmProCn = array('公司有关名词','品牌有关名词','电话号码/传真号码');
  $k=array();
  $sql = $this->sql($a[0],$a[1][1],$a[1][2],$a[1][3]);// echo("$sql <br>");
  $result=mysql_query($sql) or die('could not query com');
  $rs=mysql_num_rows($result);
  mysql_free_result($result);
  if($rs===0) return 0;
  if(strpos($a[1][1],'\\')>0) $a[1][1]=str_replace('\\','',$a[1][1]);
  $t = $this->getString($a[0],$nmProUs,$a[1][4],'us');//us: $a[1][2]
  $k[]="<tr><td class='khl khr' height=20><table class='tab fn11' cellpadding=0 cellspacing=0>
        <tr><td class='pdr5 colss' valign=top style=padding-left:12px>»</td>
        <td class=font14>$t[0] <a class=style7 href='$t[1]'>".$a[1][1]."</a> ($rs)</td></tr></table></td></tr>";
  $t = $this->getString($a[0],$nmProVn,$a[1][4],'vn');//us: $a[1][2]
  $k[]="<tr><td height=20><table class='tab fn11' cellpadding=0 cellspacing=0>
  	 <tr><td class='pdr5 colss' valign=top style=padding-left:12px><font class=colss>»</font></td>
     <td class=font14>$t[0] <a class=style7 href='$t[1]'>".$a[1][1]."</a> ($rs)</td></tr></table></td></tr>";
  $t = $this->getString($a[0],$nmProCn,$a[1][4],'cn');//us: $a[1][2]
  $k[]="<tr><td height=20><table class='tab fn11' cellpadding=0 cellspacing=0>
  	 <tr><td class=pdr5  valign=top style=padding-left:12px><font class=colss>»</font></td>
     <td class=font14>$t[0] <a class=style7 href='$t[1]'>".$a[1][1]."</a> ($rs)</td></tr></table></td></tr>"; 
  return $k;
 }
 function getString(){
  $a = func_get_args();
  $t = array();
  switch($a[0]){
   case 'company':
    $t[]=$a[1][0]; $t[]="puttype.php?ids=$a[2]&kind=search&lang=$a[3]";
    break;
   case 'trade name':
    $lnglnk = $a[3];
    if($a[3]=='us') $lnglnk = "";
    $t[]=$a[1][1]; $t[]="tradesearch".$lnglnk.".php?ids=$a[2]";
    break;
   case 'tel/fax':
    $t[]=$a[1][2]; $t[]='puttype.php?ids='.$a[2]."&kind=tel&lang=".$a[3];
	break;
  }
  return $t;
 }
}
?>